﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Net.Sockets;
using System.Text;
using System.Threading.Tasks;
using System.Timers;
using System.Windows.Forms;

namespace mazaksmooth跨平台
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        private static Socket socketClient;

        // Token: 0x04000002 RID: 2
        public static byte[] FIRST_HAND_SHANK;

        // Token: 0x04000003 RID: 3
        private Mazak mazak = new Mazak();

        // Token: 0x04000004 RID: 4
        private System.Timers.Timer timer = new System.Timers.Timer();

        // Token: 0x04000005 RID: 5
        public string[] str = new string[]
        {
            "",
            "A",
            "B",
            "C",
            "D",
            "E",
            "F",
            "G"
        };
        private void button1_Click(object sender, EventArgs e)
        {
            bool flag = this.mazak.MazakConnect("mcmes.e3.luyouxia.net", 11804);
            if (flag)
            {
                this.timer.AutoReset = true;
                this.timer.Interval = 60000.0;
                this.timer.Elapsed += this.Tick;
                this.timer.Start();
                MessageBox.Show("连接成功！");
            }
            else
            {
                MessageBox.Show("连接失败！");
            }
        }
        public void Tick(object sender, ElapsedEventArgs e)
        {
            bool flag = !this.mazak.Get_Heartbeat();
            if (flag)
            {
                this.timer.Stop();
                this.timer.Close();
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
			bool flag = false;
			short num = 0;
			Mazak.MTC_ONE_RUNNING_INFO mtc_ONE_RUNNING_INFO = default(Mazak.MTC_ONE_RUNNING_INFO);
			bool runningInfo = this.mazak.GetRunningInfo(ref mtc_ONE_RUNNING_INFO);
			if (runningInfo)
			{
				this.kuaisubeilv.Text = mtc_ONE_RUNNING_INFO.rpid_override.ToString();
				this.jingeibeilv.Text = mtc_ONE_RUNNING_INFO.ax_override.ToString();
				this.zhuzhoubeilv.Text = mtc_ONE_RUNNING_INFO.sp_override.ToString();
				this.yunxingzhuangtai.Text = mtc_ONE_RUNNING_INFO.ncsts.ToString();
				flag = mtc_ONE_RUNNING_INFO.almno == 0 || mtc_ONE_RUNNING_INFO.almno == 468 || mtc_ONE_RUNNING_INFO.almno == 72 || mtc_ONE_RUNNING_INFO.almno == 82;
				if (flag)
				{
					bool flag2 = mtc_ONE_RUNNING_INFO.ncsts == 15 || mtc_ONE_RUNNING_INFO.ncsts == 1807 || mtc_ONE_RUNNING_INFO.ncsts == 1551 || mtc_ONE_RUNNING_INFO.ncsts == 1039 || mtc_ONE_RUNNING_INFO.ncsts == 1295 || mtc_ONE_RUNNING_INFO.ncsts == 1815 || mtc_ONE_RUNNING_INFO.ncsts == 1443 || mtc_ONE_RUNNING_INFO.ncsts == 271 || mtc_ONE_RUNNING_INFO.ncsts == 1303 || mtc_ONE_RUNNING_INFO.ncsts == 1559;
					if (flag2)
					{
						this.yunxingzhuangtai.Text = 2.ToString();
					}
					else
					{
						bool flag3 = mtc_ONE_RUNNING_INFO.ncsts == 1955 || mtc_ONE_RUNNING_INFO.ncsts == 259 || mtc_ONE_RUNNING_INFO.ncsts == 1283 || mtc_ONE_RUNNING_INFO.ncsts == 1795 || mtc_ONE_RUNNING_INFO.ncsts == 1827 || mtc_ONE_RUNNING_INFO.ncsts == 1799 || mtc_ONE_RUNNING_INFO.ncsts == 1047 || mtc_ONE_RUNNING_INFO.ncsts == 1287 || mtc_ONE_RUNNING_INFO.ncsts == 1824;
						if (flag3)
						{
							this.yunxingzhuangtai.Text = 1.ToString();
						}
						else
						{
							this.yunxingzhuangtai.Text = mtc_ONE_RUNNING_INFO.ncsts.ToString();
						}
					}
				}
				else
				{
					this.yunxingzhuangtai.Text = 3.ToString();
				}
				short ncmode = mtc_ONE_RUNNING_INFO.ncmode;
				  num = ncmode;
				if (num <= 16)
				{
					if (num != 1)
					{
						if (num != 2)
						{
							if (num == 16)
							{
								this.moshi.Text = "HOME";
							}
						}
						else
						{
							this.moshi.Text = "手动";
						}
					}
					else
					{
						this.moshi.Text = "快速";
					}
				}
				else if (num != 256)
				{
					if (num != 512)
					{
						if (num == 2048)
						{
							this.moshi.Text = "MDI";
						}
					}
					else
					{
						this.moshi.Text = "TAPE";
					}
				}
				else
				{
					this.moshi.Text = "AUTO";
				}

				this.baojinghao.Text = mtc_ONE_RUNNING_INFO.almno.ToString();
				this.shedinggongjian.Text = mtc_ONE_RUNNING_INFO.prtcnt_clamp.ToString();
				this.shijigongjian.Text = mtc_ONE_RUNNING_INFO.prtcnt.ToString();
			}

			Mazak.MTC_ONE_AXIS_INFO mtc_ONE_AXIS_INFO = default(Mazak.MTC_ONE_AXIS_INFO);
			bool axisInfo = this.mazak.GetAxisInfo(ref mtc_ONE_AXIS_INFO);
			if (axisInfo)
			{
				string axisname_x = mtc_ONE_AXIS_INFO.axisname_x;
				string text = mtc_ONE_AXIS_INFO.mc_pos_x.ToString();
				string text2 = mtc_ONE_AXIS_INFO.pos_x.ToString();
				string axisname_z = mtc_ONE_AXIS_INFO.axisname_z;
				string text3 = mtc_ONE_AXIS_INFO.mc_pos_z.ToString();
				string text4 = mtc_ONE_AXIS_INFO.pos_z.ToString();
				this.jixieweizhi.Text = string.Concat(new string[]
				{
					axisname_x,
					":",
					text,
					"  ",
					axisname_z,
					":",
					text3
				});
				this.xianzaiweizhi.Text = string.Concat(new string[]
				{
					axisname_x,
					":",
					text2,
					"  ",
					axisname_z,
					":",
					text4
				});
			}
			int[] array = new int[5];
			  flag = this.mazak.Get_Remain(ref array);
			if (flag)
			{
				this.yuyidongliang.Text = "X:" + ((float)array[0] / 10000f).ToString("0.0000") + "Z:" + ((float)array[2] / 10000f).ToString("0.0000");
			}

			Mazak.MTC_ONE_PROGRAM_INFO mtc_ONE_PROGRAM_INFO = default(Mazak.MTC_ONE_PROGRAM_INFO);
			  flag = this.mazak.Get_Mainpro(ref mtc_ONE_PROGRAM_INFO);
			if (flag)
			{
				this.chengxuhao.Text = mtc_ONE_PROGRAM_INFO.wno;
				this.zhushi.Text = mtc_ONE_PROGRAM_INFO.comment;
			}
			  num = 0;
			  flag = this.mazak.Get_Ctool(ref num);
			if (flag)
			{
				this.daojuhao.Text = num.ToString();
			}

			Mazak.MTC_ONE_SPINDLE_INFO mtc_ONE_SPINDLE_INFO = default(Mazak.MTC_ONE_SPINDLE_INFO);
			  flag = this.mazak.Get_SPindleInfo(ref mtc_ONE_SPINDLE_INFO);
			if (flag)
			{
				this.shedingzhuansu.Text = mtc_ONE_SPINDLE_INFO.rot.ToString();
				this.zhuzhoufuzai.Text = mtc_ONE_SPINDLE_INFO.load.ToString();
				this.zhuzhouwendu.Text = mtc_ONE_SPINDLE_INFO.temp.ToString();
			}

		}

        private void button5_Click(object sender, EventArgs e)
		{
			richTextBox1.Clear();
			StringBuilder sb = new StringBuilder();
			int num = 0;
			byte[] array = new byte[8960];
			for (int i = 1; i < 13; i++)
			{
				Mazak.MAZ_TD_COMMON[] array2 = new Mazak.MAZ_TD_COMMON[20];
				bool flag = this.mazak.Get_TDDataAll((short)i, ref array2, ref num, ref array);
				if (flag)
				{
					for (int j = 0; j < num; j++)
					{
						sb.Append("no:");
						sb.Append(array2[j].tno.ToString() + this.str[(int)array2[j].suf]);
						sb.Append("pkno:");
						sb.Append(array2[j].pkno.ToString());
						sb.Append("公径:");
						sb.Append(((float)array2[j].nom / 10f).ToString("0.0"));

						sb.Append("x:");
						sb.Append(((float)array2[j].wearcompX / 10000f).ToString("0.0000"));
						sb.Append("z:");
						sb.Append(((float)array2[j].wearcompZ / 10000f).ToString("0.0000"));

						sb.Append("x:");
						sb.Append(((float)array2[j].maxwearX / 10000f).ToString("0.0000"));

						sb.Append("z:");
						sb.Append(((float)array2[j].maxwearZ / 10000f).ToString("0.0000"));

						sb.Append("使用时间:");
						sb.Append(((float)array2[j].usetime / 60f).ToString("0"));

						sb.Append("数量:");
						sb.Append(((float)array2[j].usenumber).ToString());

						sb.Append("寿命:");
						sb.Append(((float)array2[j].lifetime / 60f).ToString("0"));

						sb.Append("数量:");
						sb.Append(((float)array2[j].lifenumber).ToString()); 

						sb.Append("直径:");
						sb.Append(((float)array2[j].diameter / 10000f).ToString("0.0000"));

						sb.Append("suf:");
						sb.Append(array2[j].suf.ToString());
 					}
				}
			}
		}

        private void button3_Click(object sender, EventArgs e)
        {
			double num = 0.0;
			bool flag = this.mazak.Get_Macro(Convert.ToInt16(this.duqur.Text), ref num);
			if (flag)
			{
				this.durzhi.Text = num.ToString();
			}
		}

        private void button4_Click(object sender, EventArgs e)
        {
			bool flag = this.mazak.Set_Macro(Convert.ToInt16(this.xier.Text), Convert.ToDouble(this.xierzhi.Text));
			if (flag)
			{
				MessageBox.Show("写入成功！");
			}
			else
			{
				MessageBox.Show("写入失败！");
			}
		}
    }
}
